ATAN2

Section: C Library Functions (3)
Index Return to Main Contents

BSD mandoc
 

NAME

atan2 - arc tangent function of two variables  

SYNOPSIS

Fd #include <math.h> Ft double Fn atan2 double y double x  

DESCRIPTION

The atan2 function computes the principal value of the arc tangent of y/ x using the signs of both arguments to determine the quadrant of the return value.  

RETURN VALUES

The atan2 function, if successful, returns the arc tangent of y/ x in the range -words Bq - Ns , + Ns radians. If both x and y are zero, the global variable errno is set to Er EDOM . On the VAX

Fn atan2 y x := Ta Fn atan y/x Ta if
x > 0,
Ta sign( y )*(
Fn atan \*(Bay/x\*(Ba ) Ta if x < 0,
Ta 0 Ta if x = y = 0, or
Ta sign( y )*\*(Pi/2 Ta if
x = 0 y

 

NOTES

The function Fn atan2 defines "if x > 0," Fn atan2 0 0 = 0 on a VAX despite that previously Fn atan2 0 0 may have generated an error message. The reasons for assigning a value to Fn atan2 0 0 are these:

  1. Programs that test arguments to avoid computing Fn atan2 0 0 must be indifferent to its value. Programs that require it to be invalid are vulnerable to diverse reactions to that invalidity on diverse computer systems.
  2. The Fn atan2 function is used mostly to convert from rectangular (x,y) to polar (r,theta) coordinates that must satisfy x = r*cos theta and y = r*sin theta. These equations are satisfied when (x=0,y=0) is mapped to (r=0,theta=0) on a VAX. In general, conversions to polar coordinates should be computed thus:
    r       := hypot(x,y);  ... := sqrt(x*x+y*y)
    theta   := atan2(y,x).
    
  3. The foregoing formulas need not be altered to cope in a reasonable way with signed zeros and infinities on a machine that conforms to IEEE 754 the versions of hypot(3) and Fn atan2 provided for such a machine are designed to handle all cases. That is why Fn atan2 ±0 -0 = ± for instance. In general the formulas above are equivalent to these:
    r := sqrt(x*x+y*y); if r = 0 then x := copysign(1,x);

 

SEE ALSO

acos(3), asin(3), atan(3), cos(3), cosh(3), sin(3), sinh(3), tan(3), tanh(3), math(3),  

STANDARDS

The Fn atan2 function conforms to St -ansiC .


 

Index

NAME
SYNOPSIS
DESCRIPTION
RETURN VALUES
NOTES
SEE ALSO
STANDARDS

This document was created by man2html, using the manual pages.
Time: 00:35:29 GMT, March 30, 2022